local skel = fk.CreateSkill {
  name = "efengqi__yiji",
}

Fk:loadTranslationTable{
  -- 注意：要求死亡伤害也能发动 
  ["efengqi__yiji"] = "遗计",
  [":efengqi__yiji"] = "当你受到1点伤害后或死亡时，你可以执行不同的两项：1.卜算2；2.摸两张牌；3.分配两张牌。",

  ["efengqi__yiji_watch"] = "卜算2",
  ["efengqi__yiji_give"] = "分配两张牌",

  ["$efengqi__yiji1"] = "锦囊妙策，终定社稷。",
  ["$efengqi__yiji2"] = "依此计行，辽东可定。",
}

local on_use = function(self, event, target, player, data)
  local room = player.room
  local choices = room:askToChoices(player, { choices = {"efengqi__yiji_watch", "draw2", "efengqi__yiji_give"},
  min_num = 2, max_num = 2, skill_name = skel.name, cancelable = false})
  if table.contains(choices, "efengqi__yiji_watch") then
    room:askToGuanxing(player, { cards = room:getNCards(2), skill_name = skel.name})
  end
  if table.contains(choices, "draw2") then
    player:drawCards(2, skel.name)
  end
  if table.contains(choices, "efengqi__yiji_give") then
    local num = math.min(2, #player:getCardIds("he"))
    if num > 0 then
      room:askToYiji(player, { cards = player:getCardIds("he"), targets = room:getOtherPlayers(player),
      skill_name =  skel.name, min_num = num, max_num = num})
    end
  end
end

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, false, true)
  end,
  trigger_times = function (self, event, target, player, data)
    return data.damage
  end,
  on_use = on_use,
})

skel:addEffect(fk.Death, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, false, true)
  end,
  on_use = on_use,
})

--- 强制让死人弃牌
skel:addEffect(fk.Damaged, {
  mute = true,
  is_delay_effect = true,
  priority = 0.001,
  can_trigger = function (self, event, target, player, data)
    return target == player and not player:isKongcheng() and player.dead and player:hasSkill(skel.name, true, true)
  end,
  on_trigger = function (self, event, target, player, data)
    player:throwAllCards("h")
  end,
})

return skel
